package com.qdevelop.control.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.qdevelop.model.service.socket.GisSocketClient;

@SuppressWarnings("serial")
public class ServerAgentAction  extends QDevelopBaseAction{
	
	String json;
	
	public String execute() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String uri =  request.getRequestURI();
		String cmd = uri.substring(uri.lastIndexOf("/")+1,uri.indexOf("."))+":"+request.getParameter("p");
		System.out.println("cmd:"+cmd);
		json = new GisSocketClient().run(cmd);
		return SUCCESS;
	}
	
//	
//	public void getURL(String url,StringBuffer sb){
//		if(QDProperties.getInstance().getBoolean("QDevelop_Debug"))
//			System.out.println("Agent URL: "+url);
//		String sCurrentLine=null; 
//		java.io.InputStream l_urlStream=null; 
//		java.io.BufferedReader l_reader=null;
//		java.net.HttpURLConnection l_connection=null;
//		try {
//			java.net.URL l_url = new java.net.URL(url); 
//			l_connection = (java.net.HttpURLConnection) l_url.openConnection();
//			l_connection.connect(); 
//			l_urlStream = l_connection.getInputStream(); 
//			l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream)); 
//			while((sCurrentLine = l_reader.readLine()) != null){ 
//				sb.append(sCurrentLine);
//			}
//		} catch (MalformedURLException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}finally{
//			try {
//				if(l_reader!=null)
//					l_reader.close();
//				if(l_urlStream!=null)
//					l_urlStream.close();
//				l_connection=null;
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		} 
//	}

	public String getJson() {
		return json;
	}

	public void setJson(String json) {
		this.json = json;
	}
	
}
